package com.qkl.xiatang.app.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.task.TaskExecutorBuilder;
import org.springframework.boot.task.TaskSchedulerBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

@Slf4j
@Configuration
public class ThreadConfig {

    @Bean(name = "applicationThreadPool")
    ThreadPoolTaskExecutor getDataHandleExecutor(TaskExecutorBuilder builder) {
        ThreadPoolTaskExecutor taskExecutor = builder.build();
        taskExecutor.setThreadNamePrefix("app-thread-");
        return taskExecutor;
    }

    @Bean(name = "applicationThreadSchedulePool")
    ThreadPoolTaskScheduler getDataHandleScheduleExecutor(TaskSchedulerBuilder builder) {
        ThreadPoolTaskScheduler taskExecutor = new ThreadPoolTaskScheduler();
        taskExecutor.setPoolSize(10);
        taskExecutor.setThreadNamePrefix("app-thread-schedule");
        taskExecutor.initialize();
        //taskExecutor.setAwaitTerminationMillis();
        //taskExecutor.setWaitForTasksToCompleteOnShutdown();
        return taskExecutor;
    }
}
